package cn.skyclass.events
{
	import cn.skyclass.net.OperationResult;
	
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	/**
	 * RPC 调用结果事件
	 */
	public class RpcEvent extends Event
	{
		public static const RPC_RESULT:String = "rpcResult";
		public static const RPC_FAULT:String = "rpcFault";
		
		
		// 存放返回的单个 bean 对象；或 bean 列表；或操作结果信息
		public var beanData:Object;
		public var beansCollection:ArrayCollection;
		public var result:OperationResult;
		
		// 存放原始的 rpc 事件		
		public var resultEvent:ResultEvent;
		public var faultEvent:FaultEvent;
		
		// 存放额外的数据				
		public var msg:String;
		public var data:Object;
		public var dataCollection:ArrayCollection;
		
		public function RpcEvent(type:String, msg:String=""){
			super(type);
			this.msg = msg;
			this.beansCollection = new ArrayCollection();			
			this.dataCollection = new ArrayCollection();
		}
		
		override public function clone():Event{
			var e:RpcEvent = new RpcEvent(this.type, this.msg);
			e.copyProperties(this);
			return e;
		}			
		
		
		/**
		 * 从提供的对象中拷贝属性值
		 */
		public function copyProperties(source:RpcEvent):void{
			if(!source){ return; }
			
			this.beanData = source.beanData;
			this.beansCollection = source.beansCollection;
			this.result = source.result;

			this.resultEvent = source.resultEvent;
			this.faultEvent = source.faultEvent;	
					
			this.msg = source.msg;
			this.data = source.data;
			this.dataCollection = source.dataCollection;			
		}
	}
}